package com.itheima.ydd.controller;


import com.itheima.ydd.common.ResultData;
import com.itheima.ydd.entity.SysUserNew;
import com.itheima.ydd.service.ISysUserNewService;
import com.itheima.ydd.service.ISysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author author
 * @since 2022-05-22
 */
@RestController
@RequestMapping("/sys_user")
@Slf4j
@CrossOrigin
public class SysUserController {

    @Autowired
    private ISysUserService sysUserService;

    @Autowired
    private ISysUserNewService sysUserNewService;


    /**
     * @description: 用户列表分页查询
     * @author: 黄伟兴
     * @date: 2022/9/7 12:33
     * @param: [login_name, status, phone, page, limit]
     * @return: com.itheima.ydd.common.ResultData
     **/
    @GetMapping("/list")
    public ResultData getList(@RequestParam String login_name, @RequestParam String status, @RequestParam String phone, @RequestParam Integer page, @RequestParam Integer limit){
      return   sysUserService.getList(login_name,status, phone,  page,  limit);
    }

    /**
     * @description: 管理员删除
     * @author: 黄伟兴
     * @date: 2022/9/7 12:36
     * @param: [id]
     * @return: com.itheima.ydd.common.ResultData
     **/
    @GetMapping("/del")
    public ResultData deleteById(@RequestParam String id){
      return   sysUserService.deleteById(id);
    }

    /**
     * @description: 查询管理员详情
     * @author: 黄伟兴
     * @date: 2022/9/7 17:09
     * @param: [id]
     * @return: com.itheima.ydd.common.ResultData
     **/
    @GetMapping("/rowInfo")
    public ResultData getDetail(@RequestParam String id){
     return    sysUserService.getDetail(id);
    }

    /**
     * @description: 添加管理员
     * @author: 黄伟兴
     * @date: 2022/9/7 21:49
     * @param: []
     * @return: com.itheima.ydd.common.ResultData
     **/
    @PostMapping("/add")
    public ResultData add(@RequestBody SysUserNew userNew){
        System.out.println(userNew);
        return sysUserNewService.add(userNew);
    }

    /**
     * @description: 修改管理员
     * @author: 黄伟兴
     * @date: 2022/9/8 9:43
     * @param: [userNew]
     * @return: com.itheima.ydd.common.ResultData
     **/
    @PostMapping("/update")
    public ResultData update(@RequestBody SysUserNew userNew){
        return sysUserNewService.updateSysUser(userNew);
    }



}
